// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-6-4

#include "stdafx.h"
#include "netmsg.h"
#include "md5.h"
#include "aes.h"
#include <common/base/utility.h>

namespace JoyMessage
{
;

// class MC_Chat

bool MC_Chat::IsValid() const
{
    if(!__super::IsValid())
    {
        return false;
    }
    if(m_text[GetTextLength()] != 0)
    {
        return false;
    }
    return true;
}

MC_Chat* MC_Chat::Alloc(UINT dstUser, bool priv, PCSTR pszText, int s)
{
    if(s == -1)
    {
        s = (int)strlen(pszText);
    }
    MC_Chat* pChat = (MC_Chat*) new char[sizeof(MC_Chat)+s];
    JoyConstruct(pChat);
    pChat->m_size   = sizeof(MC_Chat)+s;

    memcpy(pChat->m_text, pszText, s);
    pChat->m_text[s] = 0;

    pChat->m_dstUser    = dstUser;
    pChat->m_private    = priv;

    return pChat;
}
// class MS_Chat

bool MS_Chat::IsValid() const
{
    if(!__super::IsValid())
    {
        return false;
    }
    if(m_text[GetTextLength()] != 0)
    {
        return false;
    }
    return true;
}

MS_Chat* MS_Chat::Alloc(UINT srcUser, UINT dstUser, bool priv, PCSTR pszText, int s)
{
    if(s == -1)
    {
        s = (int)strlen(pszText);
    }
    MS_Chat* pChat = (MS_Chat*) new char[sizeof(MS_Chat)+s];
    JoyConstruct(pChat);
    pChat->m_size   = sizeof(MS_Chat)+s;

    memcpy(pChat->m_text, pszText, s);
    pChat->m_text[s] = 0;

    pChat->m_srcUser    = srcUser;
    pChat->m_dstUser    = dstUser;
    pChat->m_private    = priv;

    return pChat;
}

// class MS_RegionList

bool MS_RegionList::IsValid() const
{
    if(!BaseType::IsValid())
    {
        return false;
    }

    if(sizeof(MS_RegionList)+sizeof(RegionInfo)*(m_regionCount-1) > m_size)
    {
        return false;
    }

    return true;
}



} // namespace JoyMessage